#include <bits/stdc++.h>

#define eb emplace_back
#define ep emplace
#define fi first
#define se second
#define in read<int>()
#define lin read<ll>()
#define rep(i, x, y) for(int i = (x); i <= (y); i++)
#define per(i, x, y) for(int i = (x); i >= (y); i--)

using namespace std;

using ll = long long;
using db = double;
using pii = pair < int, int >;
using vec = vector < int >;
using veg = vector < pii >;

template < typename T > T read() {
	T x = 0; bool f = 0; char ch = getchar();
	while(!isdigit(ch)) f |= ch == '-', ch = getchar();
	while(isdigit(ch)) x = x * 10 + (ch ^ 48), ch = getchar();
	return f ? -x : x;
}

template < typename T > void chkmax(T &x, const T &y) { x = x > y ? x : y; }
template < typename T > void chkmin(T &x, const T &y) { x = x < y ? x : y; }

const int N = 1e6 + 10;

int main() {
#ifdef YJR_2333_TEST
	freopen("1.in", "r", stdin);
#endif
	int n = in;
	set < pii > s;
	rep(i, 1, n) {
		int l = in, r = in;
		if(!s.size() || l > s.rbegin() -> se) s.ep(l, r);
		else {
			auto p = s.lower_bound({ l, 0 });
			auto add = [&](int x, int y) {
				if(x > y) return;
				s.ep(x, y);
			};
			auto cut = [&](pii v) {
				s.erase(v);
				int xl = v.fi, xr = v.se;
				add(max(xl, l), min(xr, r));
				add(min(xr, r) + 1, xr);
				add(xl, max(xl, l) - 1);
				return s.lower_bound({ l, 0 });
			};
			if(p != s.begin()) {
				p = prev(p);
				if(p -> se >= l) {
					p = cut(*p);
				} else p = next(p);
			}
			int len = r - l + 1;
			while(p != s.end() && len) {
				int xlen = p -> se - p -> fi + 1;
				if(xlen <= len) {
					len -= xlen; s.erase(p++);
				} else {
					int pos = p -> fi + len, rpos = p -> se;
					s.erase(p++), add(pos, rpos); len = 0;
				}
			}
			s.ep(l, r);
		}
	} int ans = 0; for(auto v : s) ans += v.se - v.fi + 1/*, cerr << v.fi << " " << v.se << endl*/;
	cout << ans << endl;
	return 0;
}
